package cn.lzm.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author lzm
 * @Date 2024/7/27
 * @description
 */
public class MockServiceProxy implements InvocationHandler {

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Class<?> returnType = method.getReturnType();
        System.out.printf("开始mock方法: %s\n", method.getName());
        if (returnType.isPrimitive()) {
            if (returnType == int.class) {
                return 100;
            }
            if (returnType == long.class) {
                return 1000L;
            }
            if (returnType == boolean.class) {
                return false;
            }
            if (returnType == double.class) {
                return 1000.25D;
            }
            if (returnType == float.class) {
                return 100.25F;
            }
            if (returnType == short.class) {
                return 20;
            }
            if (returnType == byte.class) {
                return 10;
            }
            if (returnType == char.class) {
                return 'A';
            }
        }
        return null;
    }

}
